package com.maket.jbxx.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.maket.jbxx.domain.CpAttributeType;
import com.maket.jbxx.service.ICpAttributeTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 属性与分类Controller
 * 
 * @author ruoyi
 * @date 2024-07-02
 */
@RestController
@RequestMapping("/type")
public class CpAttributeTypeController extends BaseController
{
    @Autowired
    private ICpAttributeTypeService cpAttributeTypeService;

    /**
     * 查询属性与分类列表
     */
    @RequiresPermissions("system:type:list")
    @GetMapping("/list")
    public TableDataInfo list(CpAttributeType cpAttributeType)
    {
        startPage();
        List<CpAttributeType> list = cpAttributeTypeService.selectCpAttributeTypeList(cpAttributeType);
        return getDataTable(list);
    }

    /**
     * 导出属性与分类列表
     */
    @RequiresPermissions("system:type:export")
    @Log(title = "属性与分类", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CpAttributeType cpAttributeType)
    {
        List<CpAttributeType> list = cpAttributeTypeService.selectCpAttributeTypeList(cpAttributeType);
        ExcelUtil<CpAttributeType> util = new ExcelUtil<CpAttributeType>(CpAttributeType.class);
        util.exportExcel(response, list, "属性与分类数据");
    }

    /**
     * 获取属性与分类详细信息
     */
    @RequiresPermissions("system:type:query")
    @GetMapping(value = "/{sId}")
    public AjaxResult getInfo(@PathVariable("sId") Long sId)
    {
        return success(cpAttributeTypeService.selectCpAttributeTypeBySId(sId));
    }

    /**
     * 新增属性与分类
     */
    @RequiresPermissions("system:type:add")
    @Log(title = "属性与分类", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CpAttributeType cpAttributeType)
    {
        return toAjax(cpAttributeTypeService.insertCpAttributeType(cpAttributeType));
    }

    /**
     * 批量新增
     */
    @RequiresPermissions("system:type:add")
    @Log(title = "属性与分类", businessType = BusinessType.INSERT)
    @PostMapping("batchInsertCpAttributeType")
    public AjaxResult addBatchInsertCpAttributeType(@RequestBody List<CpAttributeType> cpAttributeType)
    {

        return toAjax(cpAttributeTypeService.batchInsertCpAttributeType(cpAttributeType));
    }

    /**
     * 修改属性与分类
     */
    @RequiresPermissions("system:type:edit")
    @Log(title = "属性与分类", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CpAttributeType cpAttributeType)
    {
        return toAjax(cpAttributeTypeService.updateCpAttributeType(cpAttributeType));
    }

    /**
     * 删除属性与分类
     */
    @RequiresPermissions("system:type:remove")
    @Log(title = "属性与分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sIds}")
    public AjaxResult remove(@PathVariable Long[] sIds)
    {
        return toAjax(cpAttributeTypeService.deleteCpAttributeTypeBySIds(sIds));
    }
}
